<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
	<title>基础数据-物品分类</title>
	<meta charset="utf-8">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>libs/bootstrap-3.3.7-dist/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/reset.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/style.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/iframe.css">
</head>
<body>
	<div id="mainContent">
		<div id="mainContent_content">
			<div class="page_header"><a>物品分类</a></div>
			<div class="btn">
			<p>
				<c:if test="${isAdd }">
					<input type="button" value="同级新增" onclick="addGoodsType(${categoryPage.categoryid });" class="btn btn1"></input>
					<input type="button" value="下级新增" onclick="toAddGoodsType();" class="btn btn2"></input>
				</c:if>
				<input type="button" value="编辑" onclick="toEditGoodsType();" class="btn btn1"></input>
				<c:if test="${isDelete }">
					<input type="button" value="删除" onclick="toDeleteGoodsType();" class="btn btn_danger"></input>
				</c:if>
				<c:if test="${categoryPage.secondid < 3 }">
					<input type="button" value="查看下级" onclick="showChildType();" class="btn btn1"></input>
				</c:if>
				<c:if test="${categoryPage.secondid > 1 }">
					<input type="button" value="返回上一级" class="btn btn2" onclick="location.href='<%=basePath %>category/listCategory.do?currpage=1&categoryid=${categoryPage.firstid}'"></input>
				</c:if>
			</p>
			</div>
			<div class="tableBox box">
				<table class="table table-bordered table_text_center">
					<thead>
						<tr>
							<th></th>
							<th style="width:300px;">操作</th>
							<th>类别编码</th>
							<th>类别名称</th>
							<th>创建时间</th>
							<th>创建人</th>
							<th>备注</th>
						</tr>
					</thead>
					<tbody>
						<c:forEach items="${catagoryLilst}" var="category" varStatus="i">
							<tr onclick="selectRow(this);">
								<td><label class="radio"><input type="radio" name="operateGoodsType" value="${category.categoryid }" class="form-control"><span class="radio_icon"></span></label></td>
								<td>
								<c:if test="${isAdd && category.secondid < 3}">
									<a class="btn btn-xs btn1" onclick="addGoodsType(${category.categoryid });">下级新增</a>
								</c:if>
								<c:if test="${category.secondid < 3}">
								<a class="btn btn-xs btn2" href="<%=basePath %>category/listCategory.do?currpage=1&categoryid=${category.categoryid }">查看下级</a>
								</c:if>
								<a class="btn btn-xs btn1" onclick="editGoodsType(${category.categoryid });">编辑</a>
								<c:if test="${isDelete }">
									<a class="btn btn-xs btn_danger" onclick="confirmDeleteGoodsType(${category.categoryid });">删除</a>
								</c:if>
								</td>
								<td>${category.categorycode }</td>
								<td>${category.categoryname }</td>
								<td><fmt:formatDate value="${category.createtime }"
										type="both" /></td>
								<td>${category.name }</td>
								<td>${category.description }</td>
							</tr>
						</c:forEach>
					</tbody>
				</table>
			</div>
			<jsp:include page="/jsp/basic/page.jsp"></jsp:include>
		</div>
		<jsp:include page="/jsp/basicData/goodsType/addGoodsType.jsp"></jsp:include>
		<jsp:include page="/jsp/basicData/goodsType/editGoodsType.jsp"></jsp:include>
		<jsp:include page="/jsp/basic/prompt.jsp"></jsp:include>
	</div>
	<script src="<%=basePath %>js/jquery-3.2.1.min.js"></script>
	<script src="<%=basePath %>libs/bootstrap-3.3.7-dist/js/bootstrap.js"></script>
	<script src="<%=basePath %>js/public.js"></script>
	<script type="text/javascript">
		function selectRow(obj){
			$(obj).find('input:radio[name="operateGoodsType"]')[0].checked=true;
		}
		
		function showChildType(){
			var radio=$('input:radio[name="operateGoodsType"]:checked');
			if(!radio.val()){
				Prompt.alert("提示","请先选中需要查看下级的物品分类！");
				return;
			}
			location.href="<%=basePath %>category/listCategory.do?currpage=1&categoryid="+radio.val();
		}
		
		function toEditGoodsType(){
			var radio=$('input:radio[name="operateGoodsType"]:checked');
			if(!radio.val()){
				Prompt.alert("提示","请先选中需要编辑的物品分类！");
				return;
			}
			editGoodsType(radio.val());
		}
		
		function toAddGoodsType(){
			var radio=$('input:radio[name="operateGoodsType"]:checked');
			if(!radio.val()){
				Prompt.alert("提示","请先选中需要新增下级的物品分类！");
				return;
			}
			addGoodsType(radio.val());
		}
		
		function toDeleteGoodsType(){
			var radio=$('input:radio[name="operateGoodsType"]:checked');
			if(!radio.val()){
				Prompt.alert("删除提示","请先选中需要删除的物品分类！");
				return;
			}
			confirmDeleteGoodsType(radio.val());
		}
			
		function confirmDeleteGoodsType(id){
			var delFunc=function(){
				$.ajax({
					url:"<%=basePath %>category/delete.do",
					type:"post",
					async : false,
					dataType:"json",
					data : "categoryid="+id,
					success:function(data){
						if(data.result=="success"){
							Prompt.alert("删除提示","物品分类已删除！",Prompt.refresh);
						}
					},
					error :function(){
						Prompt.alert("删除提示","服务器无响应，请刷新页面后重试！");
					}
				});
			}
			Prompt.confirm("提示","确认要删除该物品分类吗?删除后无法恢复",delFunc);
		}
	</script>
</body>
</html>